home *** CD-ROM | disk | FTP | other *** search
/ Turnbull China Bikeride / Turnbull China Bikeride - Disc 2.iso / STUTTGART / LANG / C / LIB / UNIXLIB37B / !UnixLib37 / src / c / math < prev    next >
Text File  |  1996-11-09  |  1KB  |  92 lines

  1. /****************************************************************************
  2.  *
  3.  * $Source: /unixb/home/unixlib/source/unixlib37/src/c/RCS/math,v $
  4.  * $Date: 1996/10/30 21:58:59 $
  5.  * $Revision: 1.2 $
  6.  * $State: Rel $
  7.  * $Author: unixlib $
  8.  *
  9.  * $Log: math,v $
  10.  * Revision 1.2  1996/10/30 21:58:59  unixlib
  11.  * Massive changes made by Nick Burret and Peter Burwood.
  12.  *
  13.  * Revision 1.1  1996/04/19 21:26:42  simon
  14.  * Initial revision
  15.  *
  16.  ***************************************************************************/
  17.  
  18. static const char rcs_id[] = "$Id: math,v 1.2 1996/10/30 21:58:59 unixlib Rel $";
  19.  
  20. #include <math.h>
  21.  
  22. #if 0
  23. double
  24. cosh (register double x)
  25. {
  26.   return ((exp (x) + exp (-x)) / 2);
  27. }
  28.  
  29. double
  30. sinh (register double x)
  31. {
  32.   return ((exp (x) - exp (-x)) / 2);
  33. }
  34.  
  35. double
  36. tanh (register double x)
  37. {
  38.   register double x1, x2;
  39.  
  40.   x1 = exp (x);
  41.   x2 = exp (-x);
  42.   return ((x1 - x2) / (x1 + x2));
  43. }
  44. #endif
  45.  
  46. double
  47. frexp (register double x, register int *p)
  48. {
  49.   register int e = 0;
  50.  
  51.   if (x != 0)
  52.     {
  53.       while (x < 0.5)
  54.     {
  55.       x *= 2;
  56.       e--;
  57.     }
  58.       while (x >= 1)
  59.     {
  60.       x /= 2;
  61.       e++;
  62.     }
  63.     }
  64.  
  65.   *p = e;
  66.   return (x);
  67. }
  68.  
  69. double
  70. fmod (double x, double y)
  71. {
  72.   int ir, iy;
  73.   double r, w;
  74.  
  75.   if (y == (double)0.0)
  76.     return (x * y) / (x * y);
  77.  
  78.   r = fabs (x);
  79.   y = fabs (y);
  80.   frexp (y, &iy);
  81.   while (r >= y)
  82.     {
  83.       frexp (r, &ir);
  84.       w = ldexp (y, ir - iy);
  85.       if (w <= r)
  86.         r -= w;
  87.       else
  88.         r -= w * (double)0.5;
  89.     }
  90.   return (x >= (double)0.0) ? r : -r;
  91. }
  92.